﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations;
using WTM.Model;


namespace WTM.ViewModel.BaseData.RyVMs
{
    public partial class RyListVM : BasePagedListVM<Ry_View, RySearcher>
    {

        protected override IEnumerable<IGridColumn<Ry_View>> InitGridHeader()
        {
            return new List<GridColumn<Ry_View>>{
                this.MakeGridHeader(x => x.Xh),
                this.MakeGridHeader(x => x.Xm),
                this.MakeGridHeader(x => x.Xb),
                this.MakeGridHeader(x => x.Mz),
                this.MakeGridHeader(x => x.Sfz),
                this.MakeGridHeader(x => x.Dz),
                this.MakeGridHeader(x => x.Zzmm),
                this.MakeGridHeader(x => x.Stjkqk),
                this.MakeGridHeader(x => x.Xueli),
                this.MakeGridHeader(x => x.Hyzk),
                this.MakeGridHeader(x => x.Rwsj),
                this.MakeGridHeader(x => x.Twsj),
                this.MakeGridHeader(x => x.Jntc),
                this.MakeGridHeader(x => x.Jyqk),
                this.MakeGridHeader(x => x.Cyqk),
                this.MakeGridHeader(x => x.Xqyx),
                this.MakeGridHeader(x => x.Zfqk),
                this.MakeGridHeader(x => x.Phone),
                this.MakeGridHeader(x => x.Remark),
                this.MakeGridHeaderAction(width: 200)
            };
        }

        public override IOrderedQueryable<Ry_View> GetSearchQuery()
        {
            var query = DC.Set<Ry>()
                .CheckContain(Searcher.Xh, x=>x.Xh)
                .CheckContain(Searcher.Xm, x=>x.Xm)
                .CheckEqual(Searcher.Xb, x=>x.Xb)
                .CheckContain(Searcher.Mz, x=>x.Mz)
                .CheckContain(Searcher.Sfz, x=>x.Sfz)
                .CheckContain(Searcher.Dz, x=>x.Dz)
                .CheckContain(Searcher.Zzmm, x=>x.Zzmm)
                .CheckContain(Searcher.Stjkqk, x=>x.Stjkqk)
                .CheckEqual(Searcher.Xueli, x=>x.Xueli)
                .CheckEqual(Searcher.Hyzk, x=>x.Hyzk)
                .CheckBetween(Searcher.Rwsj?.GetStartTime(), Searcher.Rwsj?.GetEndTime(), x => x.Rwsj, includeMax: false)
                .CheckBetween(Searcher.Twsj?.GetStartTime(), Searcher.Twsj?.GetEndTime(), x => x.Twsj, includeMax: false)
                .CheckContain(Searcher.Jntc, x=>x.Jntc)
                .CheckEqual(Searcher.Jyqk, x=>x.Jyqk)
                .CheckContain(Searcher.Cyqk, x=>x.Cyqk)
                .CheckContain(Searcher.Xqyx, x=>x.Xqyx)
                .CheckContain(Searcher.Zfqk, x=>x.Zfqk)
                .CheckContain(Searcher.Phone, x=>x.Phone)
                .CheckContain(Searcher.Remark, x=>x.Remark)
                .Select(x => new Ry_View
                {
				    ID = x.ID,
                    Xh = x.Xh,
                    Xm = x.Xm,
                    Xb = x.Xb,
                    Mz = x.Mz,
                    Sfz = x.Sfz,
                    Dz = x.Dz,
                    Zzmm = x.Zzmm,
                    Stjkqk = x.Stjkqk,
                    Xueli = x.Xueli,
                    Hyzk = x.Hyzk,
                    Rwsj = x.Rwsj,
                    Twsj = x.Twsj,
                    Jntc = x.Jntc,
                    Jyqk = x.Jyqk,
                    Cyqk = x.Cyqk,
                    Xqyx = x.Xqyx,
                    Zfqk = x.Zfqk,
                    Phone = x.Phone,
                    Remark = x.Remark,
                })
                .OrderBy(x => x.ID);
            return query;
        }

    }

    public class Ry_View : Ry{

    }
}
